# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=pinentry
pkgver=1.2.0
pkgrel=0
pkgdesc="Collection of simple PIN or passphrase entry dialogs which utilize the Assuan protocol"
url="https://www.gnupg.org/aegypten2/"
arch="all"
license="GPL-2.0-or-later"
install="$pkgname.post-install $pkgname.post-upgrade $pkgname-curses-ss.post-install"
makedepends="ncurses-dev libcap-dev libgpg-error-dev libassuan-dev gcr-dev libsecret-dev"
subpackages="$pkgname-doc $pkgname-tty $pkgname-curses-ss:_curses_ss"
source="https://gnupg.org/ftp/gcrypt/pinentry/pinentry-$pkgver.tar.bz2"

prepare() {
	default_prepare

	cp -ar "$builddir" "$builddir-libsecret"
}

build() {
	_build \
		--disable-libsecret \
		--enable-pinentry-curses \
		--enable-pinentry-tty

	cd "$builddir-libsecret"
	_build \
		--enable-libsecret \
		--enable-pinentry-curses \
		--disable-pinentry-tty
}

_build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--disable-pinentry-gtk2 \
		--disable-pinentry-gnome3 \
		--disable-pinentry-qt \
		--enable-fallback-curses \
		"$@"
	make
}

check() {
	make check
}

package() {
	make -C "$builddir" DESTDIR="$pkgdir" install

	# created by post install scripts so we can override with other UI versions
	rm -f "$pkgdir"/usr/bin/pinentry
}

_curses_ss() {
	pkgdesc="Curses-based PIN or pass-phrase entry dialog for GnuPG with Secret Service support"

	install -D -m 755 "$builddir-libsecret"/curses/pinentry-curses \
		"$subpkgdir"/usr/bin/pinentry-curses-ss
}

tty() {
	pkgdesc="Minimal dumb-terminal PIN or pass-phrase entry dialog for GnuPG"

	amove usr/bin/pinentry-tty
}

sha512sums="
19cea79aa3982d1f0d75220c8e24ca38d6c49475c6f4c5aa7101151b4690db23ed316096a4a411136e716ba4eb471f48f9b09556e5c9837533c2356b9b384b63  pinentry-1.2.0.tar.bz2
"
